#include <string.h>  
#include <stdio.h>  
#include <assert.h>  
#include <math.h>  
#include "dominion.h"  
#include "dominion_helpers.h"  
#include "rngs.h" 

void checkCouncil_room( struct gameState *pre, int handPos, int p ) {
  int i, r, choice1, choice2, choice3;
  struct gameState post;

  memcpy(&post, pre, sizeof(struct gameState));
  SelectStream(2);
  PutSeed(3);  
  
  choice1 = floor(Random()*256);
  choice2 = floor(Random()*256);
  choice3 = floor(Random()*256);
  
  r = cardEffect(council_room, choice1, choice2, choice3, &post, handPos, 0);
  assert( r == 0 );

  for(i=0; i<4; i++)
    drawCard( p, pre );

  pre->numBuys++;
  assert( pre->numBuys == post.numBuys );

  for(i=0; i<pre->numPlayers; i++){
    if( i != p ){
      drawCard(i, pre);
      assert( pre->handCount[i] == post.handCount[i] );
    }
  }

  discardCard(handPos, p, pre, 0);

  assert(memcmp( &post, pre, sizeof(struct gameState)) == 0 );
}  





int main() {

  int i, k, n, handPos, p, numPlayers;

  struct gameState g;

  PutSeed(3);
  SelectStream(2);

  for(n=0; n<2000; n++) {
    for(i=0; i<sizeof(struct gameState); i++) 
      ((char *)&g)[i] = floor(Random()*256);
    
    numPlayers = floor(Random()*MAX_PLAYERS);
    p = floor(Random()*numPlayers);

    g.deckCount[p] = floor(Random()*MAX_DECK);
    g.discardCount[p] = floor(Random()*MAX_DECK);
    g.handCount[p] = floor(Random()*MAX_HAND);
	g.playedCardCount = floor(Random()*MAX_HAND);
	for(k=0; k<g.playedCardCount; k++)
		g.playedCards[k] = floor(Random()*MAX_DECK);
    g.numActions = 0;
    g.whoseTurn = p;
    g.numPlayers = numPlayers;
    handPos = floor(Random()*g.handCount[p]);    

    checkCouncil_room( &g, handPos, p );
  }

  printf("All tests PASSED!\n");
  
  return 0;

}